package com.continuing.beef.service.type.impl;

import java.util.List;

import com.continuing.beef.domain.type.BillTypeBySelect;
import com.continuing.beef.service.BeefCommonService;
import com.continuing.common.core.domain.model.LoginUser;
import com.continuing.common.utils.DateUtils;
import com.continuing.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.continuing.beef.mapper.BillTypeMapper;
import com.continuing.beef.domain.type.BillType;
import com.continuing.beef.service.type.IBillTypeService;

/**
 * 账单类型Service业务层处理
 *
 * @author ruoyi
 * @date 2021-09-16
 */
@Service
public class BillTypeServiceImpl implements IBillTypeService {

    @Autowired
    private BillTypeMapper billTypeMapper;

    @Autowired
    private BeefCommonService beefCommonService;

    /**
     * 查询账单类型
     *
     * @param id 账单类型主键
     * @return 账单类型
     */
    @Override
    public BillType selectBillTypeById(Long id) {
        return billTypeMapper.selectBillTypeById(id);
    }

    @Override
    public BillType selectBillTypeByTypeId(String typeId) {
        return billTypeMapper.selectBillTypeByTypeId(typeId);
    }

    /**
     * 查询账单类型列表
     *
     * @param billType 账单类型
     * @return 账单类型
     */
    @Override
    public List<BillType> selectBillTypeList(BillType billType, LoginUser loginUser) {
        // 根据登录人的部门进行筛选
        billType.setDeptId(
                beefCommonService.getFirmDeptIdByDeptId(loginUser.getDeptId())
        );

        return billTypeMapper.selectBillTypeList(billType);
    }

    /**
     * 选择用到的 账单类型 数据
     *
     * @param deptId 部门id
     * @return
     */
    public List<BillTypeBySelect> selectBillTypeSelectListByDeptId(Long deptId) {

        BillType billType = new BillType();

        billType.setDeptId(
                // 根据部门id查询同一公司下面客户部门的id
                beefCommonService.getFirmDeptIdByDeptId(deptId)
        );

        List<BillTypeBySelect> billTypeBySelects = billTypeMapper.selectBillTypeListBySelect(billType);
        return billTypeBySelects;
    }


    /**
     * 新增账单类型
     *
     * @param billType 账单类型
     * @return 结果
     */
    @Override
    public int insertBillType(BillType billType, LoginUser loginUser) {
        billType.setTypeId(IdUtils.simpleUUID());
        billType.setCreateTime(DateUtils.getNowDate());

        // 根据登录人的部门进行筛选
        billType.setDeptId(
                beefCommonService.getFirmDeptIdByDeptId(loginUser.getDeptId())
        );
        // 创建者
        billType.setCreateBy(loginUser.getUser().getUserId() + "");

        return billTypeMapper.insertBillType(billType);
    }

    /**
     * 修改账单类型
     *
     * @param billType 账单类型
     * @return 结果
     */
    @Override
    public int updateBillType(BillType billType) {
        billType.setUpdateTime(DateUtils.getNowDate());
        return billTypeMapper.updateBillType(billType);
    }

    /**
     * 批量删除账单类型
     *
     * @param ids 需要删除的账单类型主键
     * @return 结果
     */
    @Override
    public int deleteBillTypeByIds(Long[] ids) {
        return billTypeMapper.deleteBillTypeByIds(ids);
    }

    /**
     * 删除账单类型信息
     *
     * @param id 账单类型主键
     * @return 结果
     */
    @Override
    public int deleteBillTypeById(Long id) {
        return billTypeMapper.deleteBillTypeById(id);
    }





}
